package socket;

public class CompletionStr {

	/**
	 * 长度不足 后不空格
	 * @param args
	 * @author 郑鲁业
	 */
	public static void main(String[] args) {
		System.out.println(compStr("123", 10));
		System.out.println(compStr("123", 10).length());
	}
	public static String compStr(String str,int length){ 
		if (str!=null && str.getBytes().length<length) {
			for(int i=str.getBytes().length; i <length; i++){ 
				str= str+" "; 
				} 
			return str;
		}else if (str==null) {
			str="";
			for(int i=str.getBytes().length; i <length; i++){ 
				str= str+" "; 
				} 
			return str;
		}
		else {
			return str;
		}
	}
	
	//针对报文校验码取出的长度不足8位时前面补0
	public static String compStr0(String str,int length){
		if (str!=null && str.getBytes().length<length) {
			for(int i=str.getBytes().length; i <length; i++){ 
				str= "0"+str; 
				} 
			return str;
		}else {
			return str;
		}
	}
}
